home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / System.h < prev    next >
C/C++ Source or Header  |  1992-08-07  |  5KB  |  174 lines

  1. #ifndef System_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define System_First
  7.  
  8. #include "Object.h"
  9.  
  10. //---- class SysEvtHandler ---------------------------------------
  11. // abstract class for handling events from system resources
  12.  
  13. enum SysEventCodes {
  14.     eSysEvtRead,
  15.     eSysEvtWrite,
  16.     eSysEvtZombie,
  17.     eSysEvtSignal,
  18.     eSysEvtAsyncSignal,
  19.     eSysEvtTimeout,
  20.     eSysEvtWork
  21. };
  22.  
  23. class SysEvtHandler : public Object {
  24.     class SeqCollection *owner;
  25.     int resourceId;
  26. protected:
  27.     ~SysEvtHandler();
  28. public:
  29.     MetaDef(SysEvtHandler);
  30.     SysEvtHandler(int resource);
  31.     int GetResourceId()
  32.     { return resourceId; }
  33.     void SetResourceId(int id)
  34.     { resourceId= id; }
  35.     virtual void Notify(SysEventCodes code, int val);
  36.     virtual bool HasInterest(SysEventCodes code);
  37.     void Remove();
  38.     bool IsEqual(Object *op);
  39.     void AddOwner(SeqCollection *o);
  40.     virtual int Error(int code);
  41. };
  42.  
  43. //---- Signals -----------------------------------------------------------------
  44.  
  45. enum Signals {
  46.     eSigBus,
  47.     eSigSegmentationViolation,
  48.     eSigSystem,
  49.     eSigPipe,
  50.     eSigIllegalInstruction,
  51.     eSigQuit,
  52.     eSigInterrupt,
  53.     eSigWindowChanged,
  54.     eSigAlarm,    
  55.     eSigChild,
  56.     eSigUrgent
  57. };
  58.  
  59. //---- System ------------------------------------------------------------------
  60.  
  61. typedef void (*CallFunc)(void*, void*, void*, void*);
  62.  
  63. class System : public Object {
  64. protected:
  65.     bool done;
  66.     char *errorstr, *osid;
  67.     bool environIsCopied;
  68.  
  69.     SeqCollection *fileInputHandler;
  70.     SeqCollection *fileOutputHandler;
  71.     SeqCollection *zombieHandler;    
  72.     SeqCollection *signalHandler;    
  73.     SeqCollection *asyncSignalHandler;    
  74.     SeqCollection *timeoutHandler;
  75.     SeqCollection *workHandler;
  76.     SeqCollection *cleanupList;
  77.  
  78. public:  
  79.     static bool anyremoved;
  80.  
  81. public:
  82.     MetaDef(System);
  83.     System(char *name= "GENERIC");
  84.     virtual ~System();
  85.  
  86.     virtual bool Init();
  87.  
  88.     char *GetErrorStr()
  89.     { return errorstr; }
  90.     virtual char *GetError();
  91.     char *GetSystemId()
  92.     { return osid; }
  93.     virtual void Control();
  94.     void ExitControl();
  95.     virtual void InnerLoop(int timeout= 200);
  96.     virtual bool CanRead(int fd, int timeout);
  97.     virtual bool CanWrite(int fd, int timeout);
  98.  
  99.     virtual class Directory *MakeDirectory(char *name);
  100.     virtual void Rename(char *from, char *to);
  101.     
  102.     //---- expand the metacharacters in Pat as in the shell
  103.     virtual bool ExpandPathName(char *patbuf, int buflen);    
  104.  
  105.     virtual bool AccessPathName(char *path, int mode= 0);
  106.     virtual int GetPathInfo(char *path, int *id, long *size, int *flags, long *modtime);
  107.  
  108.     virtual bool ChangeDirectory(char *path);
  109.     virtual char *WorkingDirectory();
  110.     virtual char *HomeDirectory();
  111.     virtual char *DirName(char *pathname);
  112.     
  113.     virtual void Exit(int code, bool mode= TRUE);
  114.     virtual void Wait(unsigned int);
  115.     virtual void Abort(int code= 0);
  116.     virtual int GetPid();
  117.  
  118.     //---- pseudo tty connection --------------------------------
  119.     virtual class PttyConnection *MakePttyConnection(char *prog, char **args);
  120.  
  121.     //---- environment manipulation -----------------------------
  122.     virtual void Setenv(char *name, char *value);
  123.     // set environment variable name to value   
  124.     virtual void Unsetenv(char *name);
  125.     // remove environment variable
  126.     virtual char *Getenv(char *);
  127.  
  128.     //---- Dynamic Loading --------------------------------------
  129.     virtual Object *Load(char *progname, char *name);
  130.  
  131.     //---- handling of system events ----------------------------
  132.     virtual void AddHandler(SeqCollection *s, SysEvtHandler *h);
  133.     virtual SysEvtHandler *RemoveHandler(SeqCollection *s, SysEvtHandler *h);
  134.  
  135.     void AddFileInputHandler(SysEvtHandler *h) 
  136.     { AddHandler(fileInputHandler, h); }
  137.     void AddFileOutputHandler(SysEvtHandler *h)
  138.     { AddHandler(fileOutputHandler, h); }
  139.     void AddZombieHandler(SysEvtHandler *h)
  140.     { AddHandler(zombieHandler, h); }
  141.     void AddSignalHandler(SysEvtHandler *h)    // synch
  142.     { AddHandler(signalHandler, h); }
  143.     void AddAsyncSignalHandler(SysEvtHandler *h)
  144.     { AddHandler(asyncSignalHandler, h); }
  145.     void AddTimeoutHandler(SysEvtHandler *h)
  146.     { AddHandler(timeoutHandler, h); }
  147.     void AddWorkHandler(SysEvtHandler *h)
  148.     { AddHandler(workHandler, h); }
  149.     void *RemoveTimeoutHandler(SysEvtHandler *h)
  150.     { return RemoveHandler(timeoutHandler, h); }
  151.     void AddCleanupObject(Object*);
  152.     void Remove();
  153.  
  154.     //---- RPC --------------------------------------------------
  155.     virtual int OpenConnection(char *server, char *service);
  156.     virtual int AnnounceTcpService(char *service);
  157.     virtual int AnnounceUnixService(char *server);
  158.     virtual int AcceptConnection(int sock);
  159. };
  160.  
  161. extern System  *gSystem;
  162. extern char    *gEtDir;
  163. extern int      gDebug;
  164. extern bool     gInMain;
  165. extern char    *gProgname;
  166. extern bool     gQuitApp;
  167.  
  168. extern "C" void _exit(int code);
  169.  
  170. extern void ETInit(char **argv);
  171. extern void InitSystem();
  172.  
  173. #endif
  174.